package com.chlorine.sandbox;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Helps manage this app's database. Allows us to fetch readable/writable
 * database objects, which we can query, and provides unique id numbers.
 * 
 * @author Caroline Liu
 *
 */
public class DatabaseHelper extends SQLiteOpenHelper {

	private static final int DB_VERSION = 1;
	private static final String TABLE_NAME = "itemlistv2";
	private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME
			+ " (id INT PRIMARY KEY, title TEXT NOT NULL, "
			+ "desc TEXT, checked BOOLEAN NOT NULL);";

	/**
	 * Next available item id. First one starts at 1.
	 */
	private static int CURRENT_ID = 1;

	public DatabaseHelper(Context context, CursorFactory factory) {
		super(context, TABLE_NAME, factory, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		// stub
	}
	
	/**
	 * Return the name of the only Table we have.
	 * 
	 * @return
	 */
	public String getTableName() {
		return TABLE_NAME;
	}

	/**
	 * Return a new item id.
	 * 
	 * @return
	 */
	public int getNewId() {
		return CURRENT_ID++;
	}
	
}
